package com.example.demo.Test;

import java.util.*;

/**
 * for-each 练习
 *
 * @author Create by 崔少良 2018-06-08 下午 1:20
 */
public class ForEachTest {
    public static void main(String[] args) {
        getforEachGouZi();
        forEachStrings();
        forEachLists();
        forEachMaps();
    }
    //一对骰子的所有可能的滚法
    public static void getforEachGouZi(){
        List<String> ls = forEachGouZi();
        System.out.println(ls.size());
        ls.forEach(l->System.out.println(l));
    }
    public static List<String> forEachGouZi(){
        Collection<Face> fs = Arrays.asList(Face.values());
        List<String> ls = new ArrayList<>();
        for(Face f:fs){
            for (Face f1:fs) {
                ls.add(f+"("+f.getA()+")"+"-----"+f1+"("+f1.getA()+")");
            }
        }
        return ls;
    }
    public static void forEachStrings(){
        String[] strs = {"a","b","c"};
        for(String str:strs){
            System.out.println(str);
        }
    }
    public static void forEachLists(){
        List<String> lists = new ArrayList<>();
        lists.add("a1");
        lists.add("a2");
        lists.add("a3");
        for (String list:lists){
            System.out.println(list);
        }
        System.out.println("-----------------------------------------------------");
        lists.forEach(list->System.out.println(list));
        System.out.println("-----------------------------------------------------");
        lists.forEach(list->{
            if (list != "a1") {
                System.out.println(list);
            }
        });
    }
    public static void forEachMaps(){
        Map<String, Integer> maps = new HashMap<>();
        maps.put("ma",1);
        maps.put("mb",2);
        maps.put("mc",3);
        for (Map.Entry<String, Integer> entry : maps.entrySet()) {
            System.out.println("Item : " + entry.getKey() + " Count : " + entry.getValue());
        }
        System.out.println("-----------------------------------------------------");
        maps.forEach((k,v)->System.out.println("Item : " + k + " Count : " + v));
        System.out.println("-----------------------------------------------------");
        maps.forEach((k,v)->{
            if (v > 2) {
                System.out.println("Item : " + k + " Count : " + v);
            }
        });
    }
}
//骰子枚举类
enum Face{
    ONE(1),
    TWO(2),
    THREE(3),
    FOUR(4),
    FIVE(5),
    SIX(6);
    private int a;
    public int getA() {
        return a;
    }
    public void setA(int a) {
        this.a = a;
    }
    Face(int a){
        this.a=a;
    }
}